﻿using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Linq;

namespace TestExtensions
{
    public class TestStep : IEnumerable<TestStep>, IHasStatus
    {
        #region Constructors

        public TestStep(XElement elemStep)
        {
            Element = elemStep;
            this.LoadStatus();
            Time = Element.Element("Time").Value;
            Object = Element.Element("Obj").Value;
            Details = Element.Element("Details").Value;
            SubSteps = new ReadOnlyCollection<TestStep>(Element.Elements("Step").Select(subStepElement => new TestStep(subStepElement)).ToList());
        }

        #endregion

        #region Properties

        public XElement Element { get; private set; }

        public string Status { get; set; }

        public string Time { get; private set; }
        
        public string Object { get; private set; }
        
        public string Details { get; private set; }

        public ReadOnlyCollection<TestStep> SubSteps { get; private set; }

        #endregion

        #region Methods

        public IEnumerator<TestStep> GetEnumerator()
        {
            return SubSteps.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return SubSteps.GetEnumerator();
        }

        #endregion
    }
}